<?php
/**
 * <https://y.st./>
 * Copyright © 2017 Alex Yst <mailto:copyright@y.st>
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <https://www.gnu.org./licenses/>.
**/

$xhtml = array(
	'<{title}>' => 'NTFSInfo',
	'<{subtitle}>' => 'Written in <span title="Operating Systems 1">CS 2301</span> of <a href="http://www.uopeople.edu/">University of the People</a>, finalised on 2017-10-25',
	'<{copyright year}>' => '2017',
	'takedown' => '2017-11-01',
	'<{body}>' => <<<END
<div class="APA_title_page">
	<p>
		NTFSInfo<br/>
		Alex Yst<br/>
		University of the People
	</p>
</div>
<h2>Introduction</h2>
<p>
	This week in <span title="Operating Systems 1">CS 2301</span>, we were required to use a Windows utility called NTFSInfo to look at our hard drives&apos; number of sectors, number of clusters, and the number of bytes in each cluster.
	We were then asked to translate the number of free clusters from its decimal notation to its hexadecimal notation.
	University of the People claims to be trying to provide an open education, available to the masses, but this assignment very much goes against that mission.
	Not everyone has the Windows operating system.
	Not all of us can <strong>*afford*</strong> a copy of the Windows operating system!
	While it makes sense to suggest NTFSInfo to Windows users, there is <strong>*zero*</strong> reason to require a specific operating system or a specific utility for this assignment.
	I was only able to even complete the assignment thanks to our fellow student, Mostapha Ramadan.
	Mostapha lent me use of a Windows system remotely, allowing me to use the Windows-only utility required for the assignment.
	(Mostapha&apos;s $a[IP] address has been edited out of the screenshot for privacy reasons.)
	In this essay, I&apos;ll show how all the required information can be gotten <strong>*without*</strong> Windows and <strong>*without*</strong> NTFSInfo.
	Demanding that students have a copy of Windows (especially without any warning, as has happened with this assignment) closes education up and could have cost me my passing grade in this course had a fellow student not offered to help.
</p>
<h2>Sectors</h2>
<p>
	A disk sector is a unit of storage that exist within the hardware of the hard drive.
	The hard drive&apos;s data storage is separated into parallel tracks that circle the drive, and these tracks are further divided into the aforementioned sectors.
	Typically, a hard drive sector stores 512 bytes, but newer hard drives may be built to store 4096 bytes (Wikipedia, n.d.)
	The amount of storage a sector stores is determined by the drive itself, not the software of the computer.
	For that reason, it can&apos;t simply be changed by upgrading or replacing your operating system or applications.
	When saving data to a hard drive, the <strong>*entire*</strong> sector must be used.
	If data that needs to be saved is too big to fit into a single sector (which is very common), multiple sectors may be used.
	However, if there is leftover space in a used sector, it will simply be zeroed out.
	To put it simply, a sector is the smallest unit on the drive that can be written to.
</p>
<img src="/img/CC_BY-SA_4.0/y.st./coursework/CS2301/NTFSInfo.png" alt="NTFSInfo" class="framed-centred-image" width="804" height="625"/>
<p>
	In NTFSInfo, we can see that on the remote, virtual, Windows-based system, the main hard drive has 52 219 903 sectors.
	The drive seems unusually small, but if you remember that it&apos;s only a virtual machine, the size makes perfect sense.
	This virtual machine exists only for making it possible to complete certain assignments, so not much data needs to be stored on the virtual drive.
</p>
<p>
	NTFSInfo isn&apos;t the only tool that can show us this information.
	On a Linux-based machine, we have <code>fdisk</code>.
	While Windows uses drive letters to allow the specification of a particular volume, Linux instead uses files in the <code>/dev</code> directory.
	On Windows, the main volume is usually <code>C:\\</code>.
	On Linux, the main volume is instead usually <code>/dev/sda1</code>.
	It&apos;s worth noting that drives and volumes are <strong>*not*</strong> the same thing.
	Drives are your hardware, volumes are the logical way in which your system views what&apos;s stored on the hardware.
	<code>C:\\</code> is <strong>*not*</strong> your main hard drive, but your main <strong>*volume*</strong>, which is usually contained on the main hard drive.
	That means that if you partition your hard drive into two volumes, each volume will have it&apos;s own drive letter on Windows.
	Likewise, my Linux system has three volumes: <code>/dev/sda1</code>, <code>/dev/sda2</code>, and <code>/dev/sda5</code>.
</p>
<img src="/img/CC_BY-SA_4.0/y.st./coursework/CS2301/fdisk.png" alt="sudo fdisk --list /dev/sda1" class="framed-centred-image" width="477" height="186"/>
<p>
	When we run <code>sudo fdisk --list /dev/sda1</code> on the command line, we see the volume has 497 664 sectors.
	That seems painfully small, but that volume is actually just used for booting the system.
	Once booted, a larger volume, <code>/dev/sda5</code>, is used.
	<code>/dev/sda5</code> is encrypted though for security reasons, and attempting to decrypt it to take a look as the sectors and clusters is beyond the scope of this essay.
	The small boot volume is plenty good enough for looking at the hardware and the logical view the operating system makes of it.
</p>
<p>
	On both the Windows system and the Linux system, the number of sectors is the number of writeable segments of data storage the physical hard drive has within the space of the logical volume.
	If you used the entire drive to house a single volume, this will be the number of writeable segments on the entire drive.
	This number though is the number of writeable segments <strong>*as they exist in the hardware*</strong>, not how the operating system and file system actually <strong>*treat*</strong> the hardware.
</p>
<h2>Clusters</h2>
<p>
	On a filesystem, clusters are groups of sectors that the filesystem combines and uses as a whole, instead of using sectors individually.
	By grouping sectors into continuous clusters of data storage, the filesystem reduces the overhead of bookkeeping, but at a cost.
	Only entire clusters can be allocated for use in storing part of a given file.
	With these clusters being bigger segments, fragmentation is also reduced, as less segments are needed to hold a given file.
	However, that also means that more space is wasted, as any leftover space in a cluster used to store a file will not be allocatable to another file and will remain unused (Wikipedia, n.d.).
</p>
<p>
	The term &quot;cluster&quot; isn&apos;t always used to describe this type of grouping.
	In fact, the term &quot;clusters&quot; isn&apos;t used officially in Windows even, as the term was changed to &quot;allocation units&quot; back in the days of $a[DOS].
	The term &quot;cluster&quot; is still widely used and understood outside of Windows though, including in third-party Windows software such as the NTFSInfo application we had to use for this assignment.
	On Linux though, the term &quot;block&quot; is used to refer to a cluster of sectors (Brouwer, 2003).
</p>
<p>
	To get information on clusters on Linux, we can use the <code>tune2fs</code> command.
	This command outputs a lot of information though; more than we&apos;re interested in for this assignment.
	The output&apos;s short enough that we can look through it and find what we need, but for a cleaner screenshot, I used <code>grep</code> to sift through it and return to us only the information on blocks (clusters).
</p>
<img src="/img/CC_BY-SA_4.0/y.st./coursework/CS2301/tune2fs.png" alt="sudo tune2fs -l /dev/sda1" class="framed-centred-image" width="373" height="276"/>
<p>
	On the Windows system (see the screenshot in the &quot;Sectors&quot; section), we see that the volume has 6 527 487 clusters.
	On the Linux system, running <code>sudo tune2fs -l /dev/sda1 | grep [Bb]lock</code>, we see the (much smaller) volume has 248 832 clusters.
	The number of clusters is the number of writeable segments <strong>*as the operating system and filesystem view the volume*</strong>.
	While software could theoretically write to segments as small as sectors, in practice, this doesn&apos;t actually happen.
	Instead, multi-sector clusters are written to.
</p>
<h2>Cluster size</h2>
<p>
	The cluster size is just the number of bytes a cluster contains.
	This is the size of the smallest storage unit, <strong>*as the operating system and filesystem see it*</strong>, and will be a multiple of the sector size, as a cluster contains a whole number of sectors.
	If we were to divide cluster size by the number of bytes in a sector (512 bytes in both the Windows example screenshot and the Linux example screenshot), we&apos;d know how many sectors our clusters contain.
	The larger the cluster size, the less fragmentation will occur, as files can fit into a smaller number of clusters.
	However, the larger the cluster size, the more usable storage space will be wasted, as the remainder of a cluster left over from storing a file is simply not used.
	On the remote, virtual, Windows machine (see the &quot;Sectors&quot; section for the screenshot), the cluster size is 4096 bytes.
	Running <code>sudo tune2fs -l /dev/sda1 | grep [Bb]lock</code> on the Linux machine (see the &quot;Clusters&quot; section for the screenshot), we see the Linux machine has a cluster size of 1024 bytes.
	For whatever reason, the Windows machine is grouping eight sectors into each cluster, while the Linux machine is only grouping two sectors into each cluster.
	I can only speculate as to why this would be.
	My guess is that because the $a[ext4] filesystem, which is used on the Linux machine, doesn&apos;t tend to fragment much, it doesn&apos;t need to build as big of clusters.
	$a[NTFS] and $a[FAT] are known to fragment very badly though, so with larger cluster sizes, the fragmentation issue on Windows can be reduced.
	The problem isn&apos;t the operating system, but the underlying filesystem.
	An $a[NTFS]- or $a[FAT]-formatted drive will fragment badly on both Windows and Linux.
	When Windows is eventually upgraded to use a more modern and more dependable filesystem, it&apos;ll likely use smaller clusters too.
</p>
<h2>Converting from decimal to hexadecimal</h2>
<p>
	I&apos;m the type of person that does algebra for fun.
	I enjoy maths.
	However, even I&apos;m not crazy enough to perform base conversion by hand unless I have to.
	It&apos;s actually really simple to do this sort of thing on a calculator.
	You might need a speciality calculator for arbitrary base conversions, but a lot of calculators built for programmers can convert between decimal, hexadecimal, octal, and binary.
	On Linux, one such calculator is Galculator.
	A similar calculator application no doubt exists for other popular operating systems, such as Windows and OS X, but you&apos;ll need to look into what applications those are yourself if you need one.
	Presenting calculator choices is beyond the scope of this paper.
</p>
<img src="/img/CC_BY-SA_4.0/y.st./coursework/CS2301/galculator_0x3e6c0d.png" alt="0x3e6c0d" class="framed-centred-image" width="716" height="375"/>
<p>
	In the screenshot in the &quot;Sectors&quot; section, we can see the <code>C:\\</code> volume on the Windows machine has 4 090 893 free sectors.
	Consulting our calculator, we see that <code>4090893</code> in decimal is equal to <code>0x3e6c0d</code> in binary.
	Don&apos;t forget to add the &quot;0x&quot; prefix!
	In this example, the presence of the digits <code>c</code>, <code>d</code>, and <code>e</code> make it obvious that the number is likely in hexadecimal form.
	However, as we&apos;ll soon see, it&apos;s not always so obvious, so we should always explicitly mark hexadecimal numbers as such by using that prefix.
</p>
<img src="/img/CC_BY-SA_4.0/y.st./coursework/CS2301/galculator_0x31678.png" alt="0x31678" class="framed-centred-image" width="716" height="375"/>
<p>
	In the screenshot in the &quot;Clusters&quot; section, we see the <code>/dev/sda1</code> volume on the Linux machine has 202 358 free sectors.
	Using our calculator again, we see that that number in decimal is equal to <code>0x31678</code> in hexadecimal.
	This time, we don&apos;t have any obvious hexadecimal digits to clue us in to the fact that it&apos;s not a decimal number.
	This is why we should always use the appropriate prefixes for non-decimal numbers!
</p>
<h2>Conclusion</h2>
<p>
	As we can see, our number of sectors, number of clusters, and the number of bytes in each cluster can be found on Windows and non-Windows systems alike, and there is no need to use the NTFSInfo utility.
	University of the People should relax their assignment requirements, opening up the option to use a non-Windows operating system.
	If the university <strong>*truly*</strong> cares about making education open to the masses and affordable, they need to stop demanding that students use one of the most expensive operating systems on the market.
	Even if I <strong>*wanted*</strong> to use Windows on my machine, I couldn&apos;t afford the licensing fees.
	I&apos;m not the only student in this situation, either!
	<strong>*Suggesting*</strong> NTFSInfo as a way to get the required information is fine.
	However, <strong>*requiring*</strong> that that specific utility be used to get the info is not only pointless, but counterproductive.
</p>
<div class="APA_references">
	<h2>References:</h2>
	<p>
		Brouwer, A. (2003, February 1). The Linux kernel: Filesystems. Retrieved from <a href="https://www.win.tue.nl/~aeb/linux/lk/lk-7.html"><code>https://www.win.tue.nl/~aeb/linux/lk/lk-7.html</code></a>
	</p>
	<p>
		Wikipedia. (n.d.). Data cluster. Retrieved from <a href="https://en.wikipedia.org/wiki/Data_cluster"><code>https://en.wikipedia.org/wiki/Data_cluster</code></a>
	</p>
	<p>
		Wikipedia. (n.d.). Disk sector. Retrieved from <a href="https://en.wikipedia.org/wiki/Disk_sector"><code>https://en.wikipedia.org/wiki/Disk_sector</code></a>
	</p>
</div>
END
);
